﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jrh.Particles
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private static readonly Vector MIDDLE_OF_VIEW = new Vector(200, 200, 200);
        private ParticlesSystem ps = null;

        private System.Windows.Forms.Timer timer1;
        private System.Windows.Forms.Button butFountain;
        private System.Windows.Forms.Button butStop;
        private System.Windows.Forms.PictureBox picDisplay;
        private System.ComponentModel.IContainer components;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            Environment.GetInstance().Gravity = new Vector(0.0f, -0.02f, 0.0f);
            Environment.GetInstance().Wind = new Vector(0.0f, 0.0f, -0.2f);

            if (Environment.GetInstance().Gravity == Environment.GetInstance().Wind)
                return;

        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.butFountain = new System.Windows.Forms.Button();
            this.butStop = new System.Windows.Forms.Button();
            this.picDisplay = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.picDisplay)).BeginInit();
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Interval = 5;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // butFountain
            // 
            this.butFountain.Location = new System.Drawing.Point(8, 40);
            this.butFountain.Name = "butFountain";
            this.butFountain.Size = new System.Drawing.Size(75, 23);
            this.butFountain.TabIndex = 0;
            this.butFountain.Text = "Fountain";
            this.butFountain.Click += new System.EventHandler(this.butFountain_Click);
            // 
            // butStop
            // 
            this.butStop.Location = new System.Drawing.Point(8, 264);
            this.butStop.Name = "butStop";
            this.butStop.Size = new System.Drawing.Size(75, 23);
            this.butStop.TabIndex = 0;
            this.butStop.Text = "Stop";
            this.butStop.Click += new System.EventHandler(this.butStop_Click);
            // 
            // picDisplay
            // 
            this.picDisplay.BackColor = System.Drawing.SystemColors.Control;
            this.picDisplay.Location = new System.Drawing.Point(96, 8);
            this.picDisplay.Name = "picDisplay";
            this.picDisplay.Size = new System.Drawing.Size(368, 280);
            this.picDisplay.TabIndex = 1;
            this.picDisplay.TabStop = false;
            this.picDisplay.Paint += new System.Windows.Forms.PaintEventHandler(this.picDisplay_Paint);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.SystemColors.Control;
            this.ClientSize = new System.Drawing.Size(472, 294);
            this.Controls.Add(this.picDisplay);
            this.Controls.Add(this.butFountain);
            this.Controls.Add(this.butStop);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.picDisplay)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void timer1_Tick(object sender, System.EventArgs e)
        {
            if (!ps.Update())
            {
                picDisplay.Refresh();
                ps = null;
                timer1.Enabled = false;
            }
            else
            {
                picDisplay.Refresh();
            }
        }

        private void butFountain_Click(object sender, System.EventArgs e)
        {
            ps = new PSFountain(MIDDLE_OF_VIEW, Color.FromArgb(0, 0, 255));
            timer1.Enabled = true;
        }

        private void butStop_Click(object sender, System.EventArgs e)
        {
            ps = null;
            timer1.Enabled = false;
            this.Refresh();
        }

        private void picDisplay_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (ps == null)
                return;
            ps.Draw(e.Graphics);
        }


    }
}
